package com.flight.trans.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.flight.trans.R;
import com.flight.trans.base.BaseRecyclerAdapter;
import com.flight.trans.base.BaseViewHolder;
import com.flight.trans.bean.EnterPortTakeDetailBean.EnterPortTakeDetailData;
import com.flight.trans.global.Constant;
import com.flight.trans.util.CommonUtils;

import java.util.List;

/**
 * 出港提货
 */
public class EnterPortPickingDetailsAdapter extends BaseRecyclerAdapter<EnterPortTakeDetailData> {

    public EnterPortPickingDetailsAdapter(Context mContext, List<EnterPortTakeDetailData> mList) {
        super(mContext, mList);
    }

    @Override
    public int setContentView() {
        return R.layout.adapter_enter_take_details;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void bindData(BaseViewHolder holder, EnterPortTakeDetailData data, int position) {
        LinearLayout mLlContainerItem = holder.findViewById(R.id.mLlContainerItem);
        ImageView mIvSelected = holder.findViewById(R.id.mIvSelected);
        TextView mTvOrderNo = holder.findViewById(R.id.mTvOrderNo);
        TextView mTvDestination = holder.findViewById(R.id.mTvDestination);
        TextView mTvProductName = holder.findViewById(R.id.mTvProductName);
        TextView mTvPicking = holder.findViewById(R.id.mTvPicking);
        TextView mTvOrderCount = holder.findViewById(R.id.mTvOrderCount);
        TextView mTvPickingCount = holder.findViewById(R.id.mTvPickingCount);
        TextView mTvStorageArea = holder.findViewById(R.id.mTvStorageArea);
        TextView mTvUnusualStatus = holder.findViewById(R.id.mTvUnusualStatus) ;
        TextView mTvCreateTime = holder.findViewById(R.id.mTvCreateTime) ;

        boolean beTake = data.getState() == Constant.Be_Picking ;

        mTvOrderNo.setBackground(data.getTransferStatus() == Constant.Transport_Code ? mContext.getDrawable(R.mipmap.icon_transport) : null);

        if(beTake){
            mIvSelected.setImageDrawable(mContext.getDrawable(data.isSelected() ? R.mipmap.check_item_sel :R.mipmap.check_item));
            setTextColor(mTvOrderNo , R.color.color_blue ,data.isSelected());
            setTextColor(mTvDestination , R.color.color_blue ,data.isSelected());
            setTextColor(mTvProductName , R.color.color_blue ,data.isSelected());
            setTextColor(mTvPicking , R.color.color_blue ,data.isSelected());
            setTextColor(mTvOrderCount , R.color.color_blue ,data.isSelected());
            setTextColor(mTvPickingCount , R.color.color_blue ,data.isSelected());
            setTextColor(mTvStorageArea , R.color.color_blue ,data.isSelected());
            setTextColor(mTvUnusualStatus , R.color.color_blue ,data.isSelected());
            setTextColor(mTvCreateTime , R.color.color_blue ,data.isSelected());
        }else {
            mIvSelected.setImageDrawable(mContext.getDrawable(R.mipmap.check_item_red));
            setTextColor(mTvOrderNo , R.color.color_red ,true);
            setTextColor(mTvDestination , R.color.color_red ,true);
            setTextColor(mTvProductName , R.color.color_red ,true);
            setTextColor(mTvPicking , R.color.color_red ,true);
            setTextColor(mTvOrderCount , R.color.color_red ,true);
            setTextColor(mTvPickingCount , R.color.color_red ,true);
            setTextColor(mTvStorageArea , R.color.color_red ,true);
            setTextColor(mTvUnusualStatus , R.color.color_red ,true);
            setTextColor(mTvCreateTime , R.color.color_red ,true);
        }

        mTvOrderNo.setText(data.getOrderNo());
        mTvDestination.setText(data.getFlightNo() + "/" + data.getOrap());
        mTvProductName.setText(data.getTradeName());
        mTvPicking.setText(data.getPackName());
        mTvOrderCount.setText(String.valueOf(data.getChargeNumber()));;
        mTvPickingCount.setText(String.valueOf(data.getOutboundNumber()));
        mTvUnusualStatus.setText(data.getAnomalyCnt() != 0 ? String.valueOf(data.getAnomalyCnt()) : "无");
        mTvStorageArea.setText(data.getInwardStorageDetailData() != null && data.getInwardStorageDetailData().size() != 0 ? "已选" + data.getInwardStorageDetailData().size() + "项" : "未选区域");
        mTvCreateTime.setText(CommonUtils.getTimeNorm(data.getOrderCreateTime()));

        mTvStorageArea.setBackground(mContext.getDrawable(R.drawable.selector_line_trans_shape));
        setOnTextClickListener(mTvStorageArea , position);

        mTvUnusualStatus.setBackground(mContext.getDrawable(R.drawable.selector_line_trans_shape));
        setOnTextClickListener(mTvUnusualStatus , position);

        mTvPickingCount.setBackground(mContext.getDrawable(R.drawable.selector_line_trans_shape));
        setOnTextClickListener(mTvPickingCount , position);

        if(beTake)
            setOnItemClickListener(mLlContainerItem, position);
    }

    private void setTextColor(TextView textView ,int color, boolean isSelected){
        textView.setTextColor(mContext.getColor(isSelected ? color : R.color.text_color));
    }
}
